package com.atzzy.ysmall.ysmall_api.shopCartController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.atzzy.ysmall.ysmall_allService.ProductService.ShoppingCartServices;
import com.atzzy.ysmall.ysmall_beans.ShoppingCart;
import com.atzzy.ysmall.ysmall_common.vo.R;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author JAVAZeng
 * @Date 2022/3/1 15:27
 * @Version 1.0
 */
@RestController
@RequestMapping("shopCart")
@CrossOrigin
public class ShopCartController {

    @Reference
    private ShoppingCartServices shoppingCartServices;

    @GetMapping("cartlist")
    public R listCarts() {
        return new R(201, "success", null);
    }

    @PostMapping("list")
    public R addShoppingCart(@RequestBody ShoppingCart shoppingCart, @RequestHeader("token") String token) {
        System.out.println(token);
        System.out.println(shoppingCart);
        return shoppingCartServices.addShoppingCart(shoppingCart);
    }

    @GetMapping("mycartList")
    public R selectShoppingCart(Integer userId, @RequestHeader("token") String token) {
        return shoppingCartServices.selectShoppingCart(userId);
    }

    @PutMapping("updateCart/{cid}/{cnum}")
    public R updateCartNum(@PathVariable("cid") Integer cartId, @PathVariable("cnum") Integer cartNum, @RequestHeader("token") String token) {
        return shoppingCartServices.updateCartNum(cartId, cartNum);
    }

    @DeleteMapping("deleteCart")
    public R deleteCart(@RequestParam("cartId") Integer cartId,@RequestHeader("token") String token)
        {
            return shoppingCartServices.deleteCart(cartId);
        }

    @GetMapping("listByCids")
    public R listByCids(String cids,@RequestHeader("token") String token){
        R resultVo = shoppingCartServices.listShoppingCartsByCids(cids);
        return resultVo;
    }
}
